//
//  CBCChannelReusableView.m
//  CBCChannelControl
//
//  Created by 李雷川 on 2019/6/30.
//  Copyright © 2019 李雷川. All rights reserved.
//

#import "CBCChannelReusableView.h"
#import "CBCChannelDef.h"
#import <Masonry/Masonry.h>
@implementation CBCChannelReusableView
-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self setupUI];
    }
    return self;
}

-(void)tapClose:(UIButton *)sender{
    self.exitBlcok();
}

-(void)tapEdit:(UIButton *)sender{
    self.editBlock(self);
}

-(void)setupUI{
    [self addSubview:self.titleLabel];
    [self addSubview:self.infoLabel];
    [self addSubview:self.closeButton];
//    [self addSubview:self.editButton];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self).mas_offset(30);
        make.top.mas_equalTo(18);
    }];
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(16);
    }];
    
    [_closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).mas_offset(-30);
        make.top.mas_equalTo(18);
    }];
//    [_editButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.trailing.equalTo(self).mas_offset(-40);
//        make.centerY.mas_equalTo(self.infoLabel);
//    }];
}


-(UILabel *)titleLabel{
    if(_titleLabel == nil){
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = CBCChannelTitleColor;;
        _titleLabel.font = [UIFont fontWithName:@"NotoSansHans-Regular" size:15];
    }
    return _titleLabel;
}

-(UILabel *)infoLabel{
    if(_infoLabel == nil){
        _infoLabel = [[UILabel alloc]init];
        _infoLabel.textColor = CBCChannelInfoColor;
        _infoLabel.font = [UIFont fontWithName:@"NotoSansHans-Regular" size:13];
    }
    return _infoLabel;
}

-(UIButton *)closeButton{
    if(_closeButton == nil){
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString *image =  CBCChannelFrameworkSrcName(@"close");
        NSLog(@"image is:%@",image);
        [_closeButton setImage:CBCChanelImage(@"close") forState:UIControlStateNormal];
        [_closeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_closeButton addTarget:self action:@selector(tapClose:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeButton;
}

-(UIButton *)editButton{
    if(_editButton == nil){
        _editButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_editButton setTitle:@"编辑" forState:UIControlStateNormal];
        [_editButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [_editButton addTarget:self action:@selector(tapEdit:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editButton;
}
@end
